<?php

declare(strict_types=1);

namespace App\Controller\Kpi;

use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Validation\Annotation\Scene;
use App\Service\FriendLink as FriendLinkService;
use App\Request\FriendLinkRequest;

#[AutoController]
class FriendLinkController extends AbstractController
{
    // 友情链接列表
    public function list()
    {
        $map = [];
        $result = (new FriendLinkService())->list($map);
        return $this->returnSuccess($result, '成功');
    }
    // 添加友情链接
    #[Scene(scene: 'add', argument: 'request')]
    public function add_link(FriendLinkRequest $request)
    {
        $params = $request->validated();
        $result = (new FriendLinkService())->addFriendLink($params);
        return $this->returnSuccess($result, '保存成功');
    }
    
    // 编辑友情链接
    #[Scene(scene: 'edit', argument: 'request')]
    public function edit_link(FriendLinkRequest $request)
    {
        $params = $request->validated();
        $result = (new FriendLinkService())->editFriendLink($params['id'],$params);
        return $this->returnSuccess($result, '保存成功');
    }

    // 删除友情链接
    public function delete_link()
    {
        $id = $this->request->input('id', 0);
        if (!$id)
            return $this->returnError('请求参数错误');
        $data = (new FriendLinkService())->deleteFriendLink($id);
        return $this->returnSuccess($data, '删除成功');
    }
}
